﻿using Linguist.Dictionary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util.Props;

namespace Linguist.Language.NGram.Large
{
    /// <summary>
    /// A wrapper for LargeNGramModel base on the old LargeTrigramModel class. 
    /// 
    /// @author Anthony Rousseau, LIUM
    /// </summary>
    public class LargeTrigramModel : LargeNGramModel
    {
            /** The property that defines that maximum number of trigrams to be cached */
        [S4Integer(defaultValue = 100000)]
        public static String PROP_TRIGRAM_CACHE_SIZE = "trigramCacheSize";

        /**
        /// @param format
        /// @param urlLocation
        /// @param ngramLogFile
        /// @param maxTrigramCacheSize
        /// @param maxBigramCacheSize
        /// @param clearCacheAfterUtterance
        /// @param maxDepth
        /// @param dictionary
        /// @param applyLanguageWeightAndWip
        /// @param languageWeight
        /// @param wip
        /// @param unigramWeight
        /// @param fullSmear
         */
        public LargeTrigramModel(String format, String urlLocation,
                String ngramLogFile, int maxTrigramCacheSize,
                int maxBigramCacheSize, Boolean clearCacheAfterUtterance,
                int maxDepth, IDictionary dictionary,
                Boolean applyLanguageWeightAndWip, float languageWeight,
                double wip, float unigramWeight, Boolean fullSmear) 
            :base(format, urlLocation, ngramLogFile, maxTrigramCacheSize,
                    clearCacheAfterUtterance, (maxDepth > 3 ? 3
                            : maxDepth), dictionary,
                    applyLanguageWeightAndWip, languageWeight, wip, unigramWeight,
                    fullSmear)
        {
            // Inline conditional statement to prevent maxDepth being > to 3
            // We are in a Trigram wrapper, after all
            
        }

        /**
	    /// 
	     */
        public LargeTrigramModel() 
        {
        }

        /*
        /// (non-Javadoc)
        /// 
        /// @see
        /// edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util
        /// .props.PropertySheet)
         */
        public void newProperties(PropertySheet ps)
        {
            location = ConfigurationManagerUtils.getResource(PROP_LOCATION, ps);
            ngramLogFile = ps.getString(PROP_QUERY_LOG_FILE);
            clearCacheAfterUtterance = ps
                    .getBoolean(PROP_CLEAR_CACHES_AFTER_UTTERANCE);
            maxDepth = ps.getInt(ILanguageModel.PROP_MAX_DEPTH);
            ngramCacheSize = ps.getInt(PROP_TRIGRAM_CACHE_SIZE);
            dictionary = (IDictionary) ps.getComponent(PROP_DICTIONARY);
            applyLanguageWeightAndWip = ps
                    .getBoolean(PROP_APPLY_LANGUAGE_WEIGHT_AND_WIP);
            languageWeight = ps.getFloat(PROP_LANGUAGE_WEIGHT);
            wip = ps.getDouble(PROP_WORD_INSERTION_PROBABILITY);
            unigramWeight = ps.getFloat(PROP_UNIGRAM_WEIGHT);
            fullSmear = ps.getBoolean(PROP_FULL_SMEAR);
        }

    }
}
